<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
  /*
    // array.forEach(callback,[ thisObject])
    var database = {
      users: ["张含韵", "江一燕", "李小璐"],
      sendEmail: function (user) {
        if (this.isValidUser(user)) {
          console.log("你好，" + user);
        } else {
          console.log("抱歉，"+ user +"，你不是本家人");  
        }
      },
      isValidUser: function (user) {
        return /^张/.test(user);
      }
    };

    // 给每个人发邮件
    database.users.forEach(  // database.users中人遍历
      database.sendEmail,    // 发送邮件
      database               // 使用database代替上面标红的this
    );

    //filter
    var data = [0, 1, 2, 3];
    var arrFilter = data.filter(function(item){
      return item%2;
    });
    // console.log(arrFilter);
    var scores = [5, 8, 3, 10];
    var current = 7;

    function higherThanCurrent(score) {
      return score > current;
    }

    if (scores.every(higherThanCurrent)) {
      console.log("朕准了！");
    }else{
      console.log("不准了！");
    };

    var matrix = [
      [1, 2],
      [3, 4],
      [5, 6]
    ];
    var flatten = matrix.reduce(function(previous,current){
      return previous.concat(current);
    });
    // console.log(flatten);
    */
    console.log('******** Object.prototype.toString.call(v)  *************')
    const data = {
      a: 'aaa',
      fn: function() {
        return true
      }
    }

    const replace = function(k ,v) {
      if(typeof v === 'function') {
        //讲Object转换为string
        return Function.prototype.toString.call(v)
      }
      return v
    }

    console.log(JSON.stringify(data, replace))
  </script>
</body>
</html>